module SecureBusiness (
        secureGreet,
        secureAdd, securedAdd,
        securePowerPower,
        Role(..)
    ) where

import Authorization
import Business

-- define clearance levels
data Clearance1 = Clearance1
instance Clearance Clearance1 where
    rolesMayAllow Clearance1 = map Role ["User","Admin"]

data Clearance2 = Clearance2
instance Clearance Clearance2 where
    rolesMayAllow Clearance2 = map Role ["User","Admin"]
    rolesMustDeny Clearance2 = [Role "Guest"]

-- assign clearance levels
secureGreet      = secureFunction Clearance1 greet
secureAdd        = secureFunction Clearance2 add
securePowerPower = secureFunction Clearance2 powerPower

-- example of a function-level security control
-- the return type can be anything so its a usecase specific function
-- here we map an Integer to a String
securedAdd a b = secureAdd' . secureAdd where
    secureAdd' (Just f) = show $ f a b
    secureAdd' Nothing  = "Don't know how to count..."

